package rpc

import (
	"context"

	"bilinadmin/internal/service"

	"google.golang.org/grpc"

	pb "bilinadmin/api/pb/server"
)

type vendorHandler struct {
	*RpcBase
	pb.UnimplementedBilinVendorServer
	name string
}

// NewVendorRpcHandler 初始化 brand rpc handler
func NewVendorRpcHandler() *vendorHandler {
	return &vendorHandler{
		RpcBase:                        base,
		UnimplementedBilinVendorServer: pb.UnimplementedBilinVendorServer{},
		name:                           "rpc_vendor_handler",
	}
}

// Register 注册服务 handler
func (hl *vendorHandler) Register(server *grpc.Server) {
	pb.RegisterBilinVendorServer(server, hl)
}

// LocationToAddress 坐标转地址
func (hl *vendorHandler) LocationToAddress(ctx context.Context, req *pb.LocationToAddressReq) (*pb.LocationToAddressReply, error) {
	if req == nil {
		return nil, nil
	}
	return service.GetVendorService().LocationToAddress(ctx, req.Latitude, req.Longitude)
}

// AddressToLocation 地址转坐标
func (hl *vendorHandler) AddressToLocation(ctx context.Context, req *pb.AddressToLocationReq) (*pb.AddressToLocationReply, error) {
	if req == nil {
		return nil, nil
	}
	return service.GetVendorService().AddressToLocation(ctx, req.Address, req.Region)
}

// AddressSearch 地址搜索
func (hl *vendorHandler) AddressSearch(ctx context.Context, req *pb.AddressSearchReq) (*pb.AddressSearchReply, error) {
	if req == nil {
		return nil, nil
	}
	return service.GetVendorService().AddressSearch(ctx, req.Keyword, req.Latitude, req.Longitude)
}

// 获取app对应的cos bucket set
func (hl *vendorHandler) ListCosBucketSets(ctx context.Context, req *pb.ListCosBucketSetsReq) (*pb.ListCosBucketSetsReply, error) {
	return service.GetVendorService().ListCosBucketSets(ctx, req.App)
}

// FCCGetCosAuthorization 可信获取cos认证信息
func (hl *vendorHandler) FCCGetCosAuthorization(ctx context.Context, req *pb.GetCosAuthorizationReq) (*pb.GetCosAuthorizationReply, error) {
	return service.GetVendorService().GetCosAuthorization(ctx, req)
}
